package com.uls.questionnaire.mapper;

import java.util.List;
import com.uls.questionnaire.domain.Response;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

/**
 * 存储回答信息的Mapper接口
 * 
 * @author zxh
 * @date 2024-11-17
 */
public interface ResponseMapper 
{
    /**
     * 查询存储回答信息的
     * 
     * @param responseId 存储回答信息的主键
     * @return 存储回答信息的
     */
    public Response selectResponseByResponseId(Long responseId);

    /**
     * 查询存储回答信息的列表
     * 
     * @param response 存储回答信息的
     * @return 存储回答信息的集合
     */
    public List<Response> selectResponseList(Response response);

    /**
     * 新增存储回答信息的
     * 
     * @param response 存储回答信息的
     * @return 结果
     */
    public int insertResponse(Response response);

    /**
     * 修改存储回答信息的
     * 
     * @param response 存储回答信息的
     * @return 结果
     */
    public int updateResponse(Response response);

    /**
     * 删除存储回答信息的
     * 
     * @param responseId 存储回答信息的主键
     * @return 结果
     */
    public int deleteResponseByResponseId(Long responseId);

    /**
     * 批量删除存储回答信息的
     * 
     * @param responseIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResponseByResponseIds(Long[] responseIds);


    @Insert("INSERT INTO zxh_response (questionnaire_id, response_data, response_time, isanonymous, response_by, question_id) " +
            "VALUES (#{questionnaireId}, #{responseData}, #{responseTime}, #{isanonymous}, #{responseBy}, #{questionId})")
    int insertResponses(Response response);


    @Insert({
    "<script>",
    "INSERT INTO zxh_response (questionnaire_id, response_data, response_time, isanonymous, response_by, question_id) ",
    "VALUES ",
    "<foreach collection='responses' item='response' separator=','>",
    "(#{response.questionnaireId}, #{response.responseData}, #{response.responseTime}, #{response.isanonymous}, #{response.responseBy}, #{response.questionId})",
    "</foreach>",
    "</script>"
})
int insertResponsesBatch(@Param("responses") List<Response> responses);


      List<Response> findResponsesByQuestionnaireId(@Param("questionnaireId") Long questionnaireId);
}
